#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

void replace_all(string & str, const string & old_value, const string & new_value) {
    for(string::size_type pos(0); pos != string::npos; pos += new_value.length()) {
        if((pos = str.find(old_value,pos)) != string::npos)
            str.replace(pos, old_value.length(), new_value);
        else break;
    }
}

int main() {

    const char * p = "hello";
    string s(p);
    cout << s << endl;
    string s2 ;
    s2 = 'c';
    cout << s2 << endl;

    string s3 = "hello";
    s3 += "world";
    s3 += '!';
    cout << s3 << endl;

    int a = s3.find("wowld");
    cout << a << endl;


    string s4 = "abcd";
    s4.replace(1, 3, "1111");
    cout << "s4 = " << s4 << endl;

    string s5 = "hello";
    s5.insert(1, "111");
    cout << s5 << endl;
    s5.erase(1, 3);
    cout << s5 << endl;

    string s6 = "helloworld";
    string s7 = s6.substr(5, 5);
    cout << s7 << endl;

    string s8 = "你好, hello, !, hahah,bu";
    replace(s8.begin(), s8.end(), ',', ' ');
    cout << s8 << endl;

    string s9 = "21121";
    replace_all(s9, "21", "123");   // 12112
    cout << s9 << endl;
    return 0;
}

